package samples.spring.defns;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * xml配置文件为默认命名空间的启动测试类
 */
public class DefaultNamespaceSpringApp {

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:defns/defaultNamespaceContext.xml");

        int beanDefinitionCount = applicationContext.getBeanDefinitionCount();
        System.out.println("beanDefinitionCount:" + beanDefinitionCount);

        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        if (beanDefinitionNames != null) {
            for (String beanDefinitionName : beanDefinitionNames) {
                Object bean = applicationContext.getBean(beanDefinitionName);
                System.out.println("beanDefinitionName:" + beanDefinitionName + "  toString: " + bean.toString());

                String[] aliases = applicationContext.getAliases(beanDefinitionName);
                if(aliases != null){
                    for (String alias : aliases) {
                        System.out.println("        alias name :" + alias);
                    }
                }
            }
        }
    }
}
